<template>
  <HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
    <template #right>
      <xtx-more></xtx-more>
    </template>
   <template #default>
        <ul ref="pannel" class="goods-list">
      <li v-for="item in  HomeNew" :key="item.id">
        <RouterLink :to="`/goods/${item.id}`">
          <img :src="item.picture" alt="" />
          <p class="name">{{ item.name }}</p>
          <p class="price">&yen;{{ item.price }}</p>
        </RouterLink>
      </li>
    </ul>
   </template>
  </HomePanel>
</template>

<script>
import HomePanel from './home-panel'
import { findNew } from '@/api/home'
import { ref, onMounted } from 'vue'
export default {
  name: 'HomeNew',
  components: { HomePanel },
  data () {
    return {
      goods: []
    }
  },
  setup () { // 组合式API
    const HomeNew = ref([]) // 1.响应式数据
    async function loadNew () { // 3.定义函数，函数内部调用接口
      const res = await findNew()
      console.log('人气推荐数据', res)// 打印看看拿到数据没有
      HomeNew.value = res.data.result
    }
    onMounted(() => { // 4.调用loadNew
      loadNew()
    })
    return { // 2.return出去
      HomeNew
    }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>
